package srv

import (
	"fmt"
	"jgt-wallet/src/bll"
	"jgt-wallet/src/context"
	"jgt-wallet/src/schema"
)

// Order 示例接口
type Order struct {
	OrderBll     *bll.Order     `inject:""`
	AlipayAppBll *bll.AlipayApp `inject:""`
	WechatAppBll *bll.WechatApp `inject:""`
}

// QueryOrderResult 查询订单结果
func (a *Order) QueryOrderResult(ctx *context.Context) error {
	ctx.WriteOperateLog("QueryOrderResult", "开始查询订单结果")
	var (
		result  *schema.OrderQueryResult
		orderId string
		err     error
	)
	if orderId = ctx.Param("orderId"); orderId == "" {
		return ctx.ResErrBadRequest(fmt.Errorf("缺少必要参数"))
	}
	ctx.WriteOperateLog("QueryOrderResult", orderId)
	result, err = a.OrderBll.GetOrderResult(orderId)
	if err != nil {
		return ctx.ResErrInternalServer(err)
	}
	return ctx.ResSuccess(result)
}

// CancelOrder 取消订单
func (a *Order) CancelOrder(ctx *context.Context) error {
	var (
		orderId string
		err     error
	)
	if orderId = ctx.Param("orderId"); orderId == "" {
		return ctx.ResErrBadRequest(fmt.Errorf("缺少必要参数"))
	}
	err = a.OrderBll.CancelOrder(orderId)
	if err != nil {
		return ctx.ResErrInternalServer(err)
	}
	return ctx.ResOK()
}
